package com.ywu.application.standard.thirdExec.service;

import com.ywu.boot.context.YwuContextHolder;
import com.ywu.boot.exception.YwuRuntimeException;
import com.ywu.common.entity.PageList;
import com.ywu.common.page.PageService;
import com.ywu.common.result.CommonResult;
import com.ywu.common.utils.TimerIdGenerateUtil;
import com.ywu.file.sys.sdk.enter.YwuFileSysExec;
import com.ywu.application.standard.thirdExec.config.YwuThirdExecConfig;
import com.ywu.application.standard.thirdExec.constant.YwuThirdExecConstant;
import com.ywu.application.standard.thirdExec.data.YwuThirdExecLogsRepository;
import com.ywu.application.standard.thirdExec.data.YwuThirdExecRepository;
import com.ywu.application.standard.thirdExec.dto.YwuThirdExecDto;
import com.ywu.application.standard.thirdExec.dto.YwuThirdExecLogsDto;
import com.ywu.application.standard.thirdExec.entity.YwuThirdExecEntity;
import com.ywu.application.standard.thirdExec.entity.YwuThirdExecLogsEntity;
import com.ywu.application.standard.thirdExec.entity.YwuThirdExecVersionEntity;
import com.ywu.application.standard.thirdExec.exec.DoThirdExecCoreService;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @ClassName YwuThirdExecService
 * @Description TODO
 * @Author GroundDemo
 * @Date 2024/10/11 14:41
 * @Version 1.0
 **/
@Service
public class YwuThirdExecService {
    @Autowired
    private YwuThirdExecRepository ywuThirdExecRepository;

    @Autowired
    private YwuThirdExecVersionService ywuThirdExecVersionService;

    @Autowired
    private YwuThirdExecConfig config;

    @Autowired
    private YwuFileSysExec ywuFileSysExec;

    @Autowired
    private DoThirdExecCoreService doThirdExecCoreService;

    @Autowired
    private YwuThirdExecLogsRepository ywuThirdExecLogsRepository;

    /**
    * @Author GroundDemo
    * @Description 添加脚本执行内容
    * @Date 14:51 2024/10/11
    * @Param [ywuThirdExecDto]
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    public CommonResult<Object> createThirdExec(YwuThirdExecDto ywuThirdExecDto) {
        String tenantId = YwuContextHolder.getCurrentContext().getYwuContextTenant().getTenantId();
        // 判断当前租户下Code是否存在
        YwuThirdExecEntity search = new YwuThirdExecEntity();
        search.setCode(ywuThirdExecDto.getCode());
        search.setTenantId(tenantId);
        YwuThirdExecEntity queryRes = ywuThirdExecRepository.getEntity(search);
        if (Objects.nonNull(queryRes)) {
            return CommonResult.error().setCode(YwuThirdExecConstant.CODE_HAS_EXISTS_CODE)
                    .setErrorCode(YwuThirdExecConstant.CODE_HAS_EXISTS_ERROR_CODE)
                    .setMessage(YwuThirdExecConstant.CODE_HAS_EXISTS_ERROR_MESSAGE);
        }
        // 构建参数
        YwuThirdExecEntity ywuThirdExecEntity = new YwuThirdExecEntity();
        BeanUtils.copyProperties(ywuThirdExecDto, ywuThirdExecEntity);
        // 初始化一些参数
        ywuThirdExecEntity.setHasNotReleased(false);
        ywuThirdExecEntity.setCurrentVersion(0);
        ywuThirdExecEntity.setStatus(YwuThirdExecEntity.DRAFT_STATUS);
        // 填入创建人和创建时间
        ywuThirdExecEntity.createInfo(YwuContextHolder.getCurrentContext().getYwuContextUser().getUserAccount());
        ywuThirdExecEntity.setTenantId(tenantId);
        ywuThirdExecEntity.setId(TimerIdGenerateUtil.nextId());
        // 执行插入操作
        ywuThirdExecRepository.insertYwuThirdExec(ywuThirdExecEntity);
        return CommonResult.success(ywuThirdExecEntity.getId());
    }

    /**
    * @Author GroundDemo
    * @Description 更新脚本元信息内容
    * @Date 14:52 2024/10/11
    * @Param [ywuThirdExecDto]
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    public CommonResult<Object> updateThirdExec(YwuThirdExecDto ywuThirdExecDto) {
        // 判断ID是否存在
        String tenantId = YwuContextHolder.getCurrentContext().getYwuContextTenant().getTenantId();
        YwuThirdExecEntity search = new YwuThirdExecEntity();
        search.setTenantId(tenantId);
        search.setId(ywuThirdExecDto.getId());
        YwuThirdExecEntity queryRes = ywuThirdExecRepository.getEntity(search);
        if (Objects.isNull(queryRes)) {
            return CommonResult.error().setCode(YwuThirdExecConstant.RESOURCE_NOT_EXISTS_CODE)
                    .setErrorCode(YwuThirdExecConstant.CODE_HAS_EXISTS_ERROR_CODE)
                    .setMessage(YwuThirdExecConstant.CODE_HAS_EXISTS_ERROR_MESSAGE);
        }
        // 根据当前数据的状态，执行不同的修改
        if (queryRes.getStatus().equals(YwuThirdExecEntity.DRAFT_STATUS)) {
            // 更新原始表中的数据即可
            updateData(ywuThirdExecDto);
        } else {
            ywuThirdExecDto.setContentUrl(queryRes.getContentUrl());
            // 需要操作version表的数据
            ywuThirdExecVersionService.updateDraftVersionInfo(ywuThirdExecDto);
            // 更新当前数据的hasNotReleased字段
            YwuThirdExecEntity ywuThirdExecEntity = new YwuThirdExecEntity();
            ywuThirdExecEntity.setId(ywuThirdExecDto.getId());
            ywuThirdExecEntity.setHasNotReleased(true);
            ywuThirdExecEntity.updateInfo(YwuContextHolder.getCurrentContext().getYwuContextUser().getUserAccount());
            // 调用sql更新数据
            ywuThirdExecRepository.updateThirdExec(ywuThirdExecEntity);
        }
        return CommonResult.success(ywuThirdExecDto.getId());
    }

    /**
    * @Author GroundDemo
    * @Description 更新数据
    * @Date 15:23 2024/10/11
    * @Param [ywuThirdExecDto, queryRes]
    * @return void
    **/
    private void updateData(YwuThirdExecDto ywuThirdExecDto) {
        YwuThirdExecEntity ywuThirdExecEntity = new YwuThirdExecEntity();
        BeanUtils.copyProperties(ywuThirdExecDto, ywuThirdExecEntity);
        // 填充创建时间和创建人
        ywuThirdExecEntity.updateInfo(YwuContextHolder.getCurrentContext().getYwuContextUser().getUserAccount());
        // 调用sql更新数据
        ywuThirdExecRepository.updateThirdExec(ywuThirdExecEntity);
    }

    /**
    * @Author GroundDemo
    * @Description 删除脚本信息
    * @Date 14:53 2024/10/11
    * @Param [ywuThirdExecDto]
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    @Transactional
    public CommonResult<Object> deleteThirdExec(YwuThirdExecDto ywuThirdExecDto) {
        // 判断ID是否存在
        String tenantId = YwuContextHolder.getCurrentContext().getYwuContextTenant().getTenantId();
        YwuThirdExecEntity search = new YwuThirdExecEntity();
        search.setTenantId(tenantId);
        search.setId(ywuThirdExecDto.getId());
        YwuThirdExecEntity queryRes = ywuThirdExecRepository.getEntity(search);
        if (Objects.isNull(queryRes)) {
            return CommonResult.success(null);
        }
        // 根据ID删除数据
        YwuThirdExecEntity ywuThirdExecEntity = new YwuThirdExecEntity();
        ywuThirdExecEntity.setId(ywuThirdExecDto.getId());
        ywuThirdExecRepository.deleteThirdExecById(ywuThirdExecEntity);
        // 删除历史版本数据
        YwuThirdExecVersionEntity ywuThirdExecVersionEntity = new YwuThirdExecVersionEntity();
        ywuThirdExecVersionEntity.setResourceId(ywuThirdExecDto.getId());
        ywuThirdExecVersionService.deleteExecVersions(ywuThirdExecVersionEntity);
        return CommonResult.success(null);
    }

    /**
    * @Author GroundDemo
    * @Description 分页查询脚本信息数据
    * @Date 14:55 2024/10/11
    * @Param [ywuThirdExecDto]
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    public CommonResult<Object> queryThirdExecPageList(YwuThirdExecDto ywuThirdExecDto) {
        String tenantId = YwuContextHolder.getCurrentContext().getYwuContextTenant().getTenantId();
        ywuThirdExecDto.setTenantId(tenantId);
        // 查询所有的数量
        int count = ywuThirdExecRepository.queryCount(ywuThirdExecDto);
        // 构建分页参数
        PageService.execPageStartAndEnd(ywuThirdExecDto.getPageInfo());
        List<YwuThirdExecEntity> entityList = ywuThirdExecRepository.queryPageList(ywuThirdExecDto);
        if (CollectionUtils.isEmpty(entityList)) {
            PageList<YwuThirdExecEntity> res = new PageList<>(ywuThirdExecDto.getPageInfo().getPageIndex(), ywuThirdExecDto.getPageInfo().getPageSize(),
                    0, new ArrayList<>());
            return CommonResult.success(res);
        }
        // 查询所有ID所对应的草稿版本的数据，后续进行填充
        List<String> resourceIds = entityList.stream().map(YwuThirdExecEntity::getId).collect(Collectors.toList());
        List<YwuThirdExecVersionEntity> versionEntityList = ywuThirdExecVersionService.queryDraftListByResourceIds(resourceIds);
        if (CollectionUtils.isEmpty(versionEntityList)) {
            PageList<YwuThirdExecEntity> resPageList = new PageList<>(ywuThirdExecDto.getPageInfo().getPageIndex(), ywuThirdExecDto.getPageInfo().getPageSize(),
                    count, entityList);
            return CommonResult.success(resPageList);
        }
        // 构建MAP，方便后续填充
        Map<String, YwuThirdExecVersionEntity> ywuThirdExecVersionEntityMap = versionEntityList.stream().collect(Collectors.toMap(YwuThirdExecVersionEntity::getResourceId, res -> res,
                (v1, v2) -> v1));
        // 分页查询不需要文档数据，将其置空
        entityList.forEach(res -> {
            if (ywuThirdExecVersionEntityMap.containsKey(res.getId())) {
                YwuThirdExecVersionEntity entity = ywuThirdExecVersionEntityMap.get(res.getId());
                res.setExecParam(entity.getExecParam());
                res.setExecType(entity.getExecType());
                res.setDescription(entity.getDescription());
                res.setContentUrl(entity.getContentUrl());
            }
        });
        // 构建pageList对象
        PageList<YwuThirdExecEntity> resPageList = new PageList<>(ywuThirdExecDto.getPageInfo().getPageIndex(), ywuThirdExecDto.getPageInfo().getPageSize(),
                count, entityList);
        return CommonResult.success(resPageList);
    }

    /**
    * @Author GroundDemo
    * @Description 上传执行脚本文件
    * @Date 11:44 2024/10/12
    * @Param [file, id]
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    public CommonResult<Object> uploadThirdExecFile(MultipartFile file, String id) {
        // 校验文件类型
        String filename = file.getOriginalFilename();
        if (StringUtils.isEmpty(filename)) {
            return CommonResult.error().setCode(YwuThirdExecConstant.FILE_NAME_IS_EMPTY_CODE)
                    .setErrorCode(YwuThirdExecConstant.FILE_NAME_IS_EMPTY_ERROR_CODE)
                    .setMessage(YwuThirdExecConstant.FILE_NAME_IS_EMPTY_ERROR_MESSAGE);
        }
        String fileType = filename.substring(filename.lastIndexOf(".") + 1);
        // 根据ID查询数据
        YwuThirdExecEntity search = new YwuThirdExecEntity();
        search.setId(id);
        search.setTenantId(YwuContextHolder.getCurrentContext().getYwuContextTenant().getTenantId());
        YwuThirdExecEntity queryRes = ywuThirdExecRepository.getEntity(search);
        // 校验文件类型和后缀是否匹配
        String type = YwuThirdExecConstant.EXEC_TYPE_FILE_TYPE_MAP.get(queryRes.getExecType());
        if (!StringUtils.equalsIgnoreCase(type, fileType)) {
            return CommonResult.error().setCode(YwuThirdExecConstant.FILE_TYPE_EXCEPTION_CODE)
                    .setErrorCode(YwuThirdExecConstant.FILE_TYPE_EXCEPTION_ERROR_CODE)
                    .setMessage(YwuThirdExecConstant.FILE_TYPE_EXCEPTION_ERROR_MESSAGE);
        }
        File fileDir = new File(config.getTempFilePath());
        if (!fileDir.exists() && !fileDir.mkdirs()) {
            throw new YwuRuntimeException("file path make error");
        }
        // 写入文件并调用sys的sdk进行文件的上传
        String tempFilePath = config.getTempFilePath() + File.separator + filename;
        File newFile = new File(tempFilePath);
        try {
            FileUtils.copyInputStreamToFile(file.getInputStream(), newFile);
        } catch (IOException e) {
            throw new YwuRuntimeException("file copy error " + e.getMessage());
        }
        Map<String, String> uploadRes = ywuFileSysExec.upload(newFile, true);
        // 删除临时文件
        newFile.delete();
        if (uploadRes.get("code").equals("200")) {
            doAfterInfo(uploadRes, queryRes);
            return CommonResult.success(null);
        } else {
            return CommonResult.error().setCode(YwuThirdExecConstant.FILE_UPLOAD_ERROR_CODE)
                    .setErrorCode(YwuThirdExecConstant.FILE_UPLOAD_ERROR_ERROR_CODE)
                    .setMessage(YwuThirdExecConstant.FILE_UPLOAD_ERROR_ERROR_MESSAGE);
        }
    }

    /**
    * @Author GroundDemo
    * @Description 执行文件上传成功后的操作
    * @Date 11:59 2024/10/12
    * @Param [uploadRes, queryRes]
    * @return void
    **/
    private void doAfterInfo(Map<String, String> uploadRes, YwuThirdExecEntity queryRes) {
        if (queryRes.getStatus().equals(YwuThirdExecEntity.DRAFT_STATUS)) {
            // 当前数据为草稿，则直接修改原始数据即可
            YwuThirdExecEntity ywuThirdExecEntity = new YwuThirdExecEntity();
            ywuThirdExecEntity.setContentUrl(uploadRes.get("fileUrl"));
            ywuThirdExecEntity.setId(queryRes.getId());
            ywuThirdExecEntity.updateInfo(YwuContextHolder.getCurrentContext().getYwuContextUser().getUserAccount());
            ywuThirdExecRepository.updateThirdExec(ywuThirdExecEntity);
        } else {
            // 当前数据为已发布，则修改version表中的数据，并将当前数据的状态改为存在草稿版本
            ywuThirdExecVersionService.updateVersionContentUrl(uploadRes, queryRes);
            YwuThirdExecEntity ywuThirdExecEntity = new YwuThirdExecEntity();
            ywuThirdExecEntity.setId(queryRes.getId());
            ywuThirdExecEntity.setHasNotReleased(true);
            ywuThirdExecEntity.updateInfo(YwuContextHolder.getCurrentContext().getYwuContextUser().getUserAccount());
            // 调用sql更新数据
            ywuThirdExecRepository.updateThirdExec(ywuThirdExecEntity);
        }
    }

    /**
     * @Author GroundDemo
     * @Description 发布脚本信息
     * @Date 12:45 2024/10/12
     * @Param [ywuThirdExecDto]
     * @return com.ywu.common.result.CommonResult<java.lang.Object>
     **/
    public CommonResult<Object> publishThirdExecInfo(YwuThirdExecDto ywuThirdExecDto) {
        // 根据ID查询数据
        YwuThirdExecEntity search = new YwuThirdExecEntity();
        search.setId(ywuThirdExecDto.getId());
        search.setTenantId(YwuContextHolder.getCurrentContext().getYwuContextTenant().getTenantId());
        YwuThirdExecEntity queryRes = ywuThirdExecRepository.getEntity(search);
        if (Objects.isNull(queryRes)) {
            return CommonResult.error().setCode(YwuThirdExecConstant.RESOURCE_NOT_EXISTS_CODE)
                    .setErrorCode(YwuThirdExecConstant.RESOURCE_NOT_EXISTS_ERROR_CODE)
                    .setMessage(YwuThirdExecConstant.RESOURCE_NOT_EXISTS_ERROR_MESSAGE);
        }
        // 判断当前数据是否为草稿状态或者存在草稿版本
        if (queryRes.getStatus().equals(YwuThirdExecEntity.DRAFT_STATUS) || queryRes.getHasNotReleased()) {
            doPublish(queryRes);
            return CommonResult.success(null);
        } else {
            return CommonResult.error().setCode(YwuThirdExecConstant.RESOURCE_NO_DRAFT_VERSION_TO_PUBLISH_CODE)
                    .setErrorCode(YwuThirdExecConstant.RESOURCE_NO_DRAFT_VERSION_TO_PUBLISH_ERROR_CODE)
                    .setMessage(YwuThirdExecConstant.RESOURCE_NO_DRAFT_VERSION_TO_PUBLISH_ERROR_MESSAGE);
        }
    }

    /**
    * @Author GroundDemo
    * @Description 发布脚本
    * @Date 14:39 2024/10/12
    * @Param [queryRes]
    * @return void
    **/
    private void doPublish(YwuThirdExecEntity queryRes) {
        if (queryRes.getStatus().equals(YwuThirdExecEntity.DRAFT_STATUS)) {
            // 草稿版本的数据直接添加到version表中
            ywuThirdExecVersionService.publishNewestVersion(queryRes);
            // 更新原始表中数据的currentVersion以及hasNotReleased字段
            YwuThirdExecEntity ywuThirdExecEntity = new YwuThirdExecEntity();
            ywuThirdExecEntity.setCurrentVersion(queryRes.getCurrentVersion() + 1);
            ywuThirdExecEntity.setHasNotReleased(false);
            ywuThirdExecEntity.setStatus(YwuThirdExecEntity.ONLINE_STATUS);
            ywuThirdExecEntity.setId(queryRes.getId());
            ywuThirdExecRepository.updateThirdExec(ywuThirdExecEntity);
        } else {
            // 草稿版本的数据需要修改版本数,并且将草稿版本的数据替换掉当前数据表中的数据
            YwuThirdExecVersionEntity versionInfo = ywuThirdExecVersionService.publishDraftVersion(queryRes);
            YwuThirdExecEntity ywuThirdExecEntity = new YwuThirdExecEntity();
            BeanUtils.copyProperties(versionInfo, ywuThirdExecEntity);
            ywuThirdExecEntity.setCurrentVersion(queryRes.getCurrentVersion() + 1);
            ywuThirdExecEntity.setHasNotReleased(false);
            ywuThirdExecEntity.setStatus(YwuThirdExecEntity.ONLINE_STATUS);
            ywuThirdExecEntity.setId(queryRes.getId());
            ywuThirdExecRepository.updateThirdExec(ywuThirdExecEntity);
        }
    }

    /**
    * @Author GroundDemo
    * @Description 执行脚本
    * @Date 15:00 2024/10/11
    * @Param [ywuThirdExecDto]
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    public CommonResult<Object> doThirdExec(YwuThirdExecDto ywuThirdExecDto) {
        if (StringUtils.isAllEmpty(ywuThirdExecDto.getCode(), ywuThirdExecDto.getId())) {
            return CommonResult.error().setCode(YwuThirdExecConstant.RESOURCE_NOT_EXISTS_CODE)
                    .setErrorCode(YwuThirdExecConstant.CODE_HAS_EXISTS_ERROR_CODE)
                    .setMessage(YwuThirdExecConstant.CODE_HAS_EXISTS_ERROR_MESSAGE);
        }
        // 根据ID查询数据
        YwuThirdExecEntity search = new YwuThirdExecEntity();
        if (StringUtils.isNotEmpty(ywuThirdExecDto.getCode())) {
            search.setCode(ywuThirdExecDto.getCode());
        } else {
            search.setId(ywuThirdExecDto.getId());
        }
        search.setTenantId(YwuContextHolder.getCurrentContext().getYwuContextTenant().getTenantId());
        YwuThirdExecEntity queryRes = ywuThirdExecRepository.getEntity(search);
        if (Objects.isNull(queryRes)) {
            return CommonResult.error().setCode(YwuThirdExecConstant.RESOURCE_NOT_EXISTS_CODE)
                    .setErrorCode(YwuThirdExecConstant.CODE_HAS_EXISTS_ERROR_CODE)
                    .setMessage(YwuThirdExecConstant.CODE_HAS_EXISTS_ERROR_MESSAGE);
        }
        // 判断当前是否存在可执行的文件
        if (StringUtils.isEmpty(queryRes.getContentUrl())) {
            return CommonResult.error().setCode(YwuThirdExecConstant.RESOURCE_NO_EXEC_CONTENT_CODE)
                    .setErrorCode(YwuThirdExecConstant.RESOURCE_NO_EXEC_CONTENT_ERROR_CODE)
                    .setMessage(YwuThirdExecConstant.RESOURCE_NO_EXEC_CONTENT_ERROR_MESSAGE);
        }
        // 构建参数
        queryRes.setExecParam(ywuThirdExecDto.getExecParam());
        String execRes = doThirdExecCoreService.exec(queryRes);
        return CommonResult.success(execRes);
    }

    /**
    * @Author GroundDemo
    * @Description 分页查询执行日志
    * @Date 15:03 2024/10/11
    * @Param [ywuThirdExecDto]
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    public CommonResult<Object> queryThirdExecLog(YwuThirdExecDto ywuThirdExecDto) {
        if (StringUtils.isAllEmpty(ywuThirdExecDto.getId(), ywuThirdExecDto.getCode())) {
            // 如果id和code都没传的话默认返回空
            return CommonResult.success(new PageList<>(ywuThirdExecDto.getPageInfo().getPageIndex(),
                    ywuThirdExecDto.getPageInfo().getPageSize(), 0, new ArrayList<>()));
        }
        // 校验服务是否存在
        YwuThirdExecEntity search = new YwuThirdExecEntity();
        if (StringUtils.isNotEmpty(ywuThirdExecDto.getCode())) {
            search.setCode(ywuThirdExecDto.getCode());
        } else {
            search.setId(ywuThirdExecDto.getId());
        }
        search.setTenantId(YwuContextHolder.getCurrentContext().getYwuContextTenant().getTenantId());
        YwuThirdExecEntity queryRes = ywuThirdExecRepository.getEntity(search);
        if (Objects.isNull(queryRes)) {
            return CommonResult.error().setCode(YwuThirdExecConstant.RESOURCE_NOT_EXISTS_CODE)
                    .setErrorCode(YwuThirdExecConstant.CODE_HAS_EXISTS_ERROR_CODE);
        }
        YwuThirdExecLogsDto ywuThirdExecLogsDto = new YwuThirdExecLogsDto();
        ywuThirdExecLogsDto.setResourceId(ywuThirdExecDto.getId());
        ywuThirdExecLogsDto.setCode(ywuThirdExecDto.getCode());
        ywuThirdExecLogsDto.setExecVersion(ywuThirdExecDto.getCurrentVersion());
        ywuThirdExecLogsDto.setPageInfo(ywuThirdExecDto.getPageInfo());
        // 查询数量
        int count = ywuThirdExecLogsRepository.queryCount(ywuThirdExecLogsDto);
        // 查询分页
        PageService.execPageStartAndEnd(ywuThirdExecDto.getPageInfo());
        List<YwuThirdExecLogsEntity> entityList = ywuThirdExecLogsRepository.queryList(ywuThirdExecLogsDto);
        PageList<YwuThirdExecLogsEntity> res = new PageList<>(ywuThirdExecDto.getPageInfo().getPageIndex(),
                ywuThirdExecDto.getPageInfo().getPageSize(), count, entityList);
        return CommonResult.success(res);
    }
}
